<?php
$objXajax->registerFunction('frmaccount_loadGrid');
$objXajax->registerFunction('frmaccount_edit');
$objXajax->registerFunction('frmaccount_save');
function frmaccount_loadGrid()
{ 
    global $lang,$path;
    $objResponse =  new xajaxResponse();// dong luon luon co khi goi ham ajax
    $arrGrid = frmaccount_getGrid();  
    $oTbs =  new clsTinyButStrong();
    $oTbs->LoadTemplate('templates/'.$lang.'/'.$path.'/cus_account_grid.html');
    $oTbs->MergeBlock('blk_data', $arrGrid);
    $oTbs->Show(TBS_NOTHING);
    $objResponse->addAssign('frmaccount_divGrid', 'innerHTML', $oTbs->Source);
    $objResponse->addScriptCall("dataTableObj.CreatDataTable('frmaccount_tbl');");     
    $objResponse->addScript('changeWaiting(1);');                        
    return $objResponse->getXML(); // dong luon luon co khi goi ham ajax   
}
function frmaccount_getGrid()
{
    global $objDbSelect,$hotel_id;
    $power_id = POWER_SUB_CUSTOMER;
    $sqlSelect = "  Select * from tbl_user where power_type_id=$power_id and hotel_id = $hotel_id";
          // echo    $sqlSelect; die();     
    return $objDbSelect->GetArray($sqlSelect);
} 

function frmaccount_edit($id){
        global $objDbSelect;
        $objResponse =  new xajaxResponse();
        $sql = " SELECT * FROM tbl_user WHERE id = '$id' ";
        $arr = $objDbSelect->GetArray($sql);
        
        $email        = addslashes($arr[0]['email']); 
        $phone     = addslashes($arr[0]['phone']);
        
        $address =htmlspecialchars_decode($arr[0]['address']) ;
        $username =htmlspecialchars_decode($arr[0]['username']) ;
        $objResponse->addAssign('frmaccount_txtAddress','value',$address);
        $objResponse->addAssign('frmaccount_txtUsername','value',$username);
        
        $objResponse->addScript("$('#frmaccount_txtEmail').val('$email');"); 
        $objResponse->addScript("$('#frmaccount_txtPhone').val('$phone');"); 
        $objResponse->addScript('changeWaiting(1);');
        return $objResponse->getXML();   
    }
    
    function frmaccount_save($params)
{
    global $objDbSelect,$user_id,$tbl_postfix;
    $objResponse =  new xajaxResponse();  
    $email =addslashes($params['txtEmail']) ;
    $address =addslashes($params['txtAddress']) ;
    $phone =addslashes($params['txtPhone']) ;
       
    $edit = $params['hdEdit'];
    $id = $params['hdId'];
    $sql = ""; 
    if($edit!=1){
      $objResponse->addScript('frmaccount_alertSelect();');  
    }else{
       $sql ="UPDATE tbl_user SET email = '$email',address = '$address',phone = '$phone',
             user_update = '$user_id',date_update = now() WHERE id =$id"; 
        $objDbSelect->Execute($sql); 
        $objResponse->addScript('changeWaiting(1);');
        $objResponse->addScript('xajax_frmaccount_loadGrid();');     
    }
    return $objResponse->getXML();
} 
?>
